<?php
$id = $_GET['id'];
    include_once('connect.php');
    $query = mysql_query("select * from calendar where id='$id'"); 
    $row = mysql_fetch_array($query); 
    if($row){ 
        $id = $row['id']; 
        $title = $row['title']; 
        $starttime = $row['starttime']; 
        $start_d = date("Y-m-d",$starttime); 
        $start_h = date("H",$starttime); 
        $start_m = date("i",$starttime); 
         
        $endtime = $row['endtime']; 
        if($endtime==0){ 
            $end_d = $startdate; 
            $end_chk = ''; 
            $end_display = "style='display:none'"; 
        }else{ 
            $end_d = date("Y-m-d",$endtime); 
            $end_h = date("H",$endtime); 
            $end_m = date("i",$endtime); 
            $end_chk = "checked"; 
            $end_display = "style=''"; 
        } 
         
        $allday = $row['allday']; 
        if($allday==1){ 
            $display = "style='display:none'"; 
            $allday_chk = "checked"; 
        }else{ 
            $display = "style=''"; 
            $allday_chk = ''; 
        } 
?>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css"> 
<div class="fancy"> 
    <h3>编辑事件</h3> 
    <form id="add_form" action="do.php" method="post"> 
    <input type="hidden" name="action" value="edit">
    <input type="hidden" name="id" id="eventid" value="<?php echo $id;?>"> 
    <p>日程内容：<input type="text" class="input" name="event" id="event" style="width:320px"  
placeholder="记录你将要做的一件事..." value="<?php echo $title;?>"></p> 
    <p>开始时间：<input type="text" class="input datepicker" name="startdate"  
id="startdate" value="<?php echo $start_d;?>" readonly> 
    <span id="sel_start" <?php echo $display;?>><select name="s_hour"> 
        <option value="<?php echo $start_h;?>" selected><?php echo $start_h;?></option> 
        <option value="00">00</option> 
        ...//这里省略多个option，下同 
    </select>: 
    <select name="s_minute"> 
        <option value="<?php echo $start_m;?>" selected><?php echo $start_m;?></option> 
        <option value="00">00</option> 
        ... 
    </select> 
    </span> 
    </p> 
    <p id="p_endtime" <?php echo $end_display;?>>结束时间：<input type="text" class="input datepicker"  
name="enddate" id="enddate" value="<?php echo $end_d;?>" readonly> 
    <span id="sel_end"  <?php echo $display;?>><select name="e_hour"> 
        <option value="<?php echo $end_h;?>" selected><?php echo $end_h;?></option> 
        ... 
    </select>: 
    <select name="e_minute"> 
        <option value="<?php echo $end_m;?>" selected><?php echo $end_m;?></option> 
        ... 
    </select> 
    </span> 
    </p> 
    <p> 
    <label><input type="checkbox" value="1" id="isallday" name="isallday" <?php echo $allday_chk;?>>  
全天</label> 
    <label><input type="checkbox" value="1" id="isend" name="isend" <?php echo $end_chk;?>> 结束时间</label> 
    <label><input type="checkbox" value="1" name="is_public"> 是否公开</label>
    </p> 
    <div class="sub_btn"><span class="del"><input type="button" class="btn btn_del" id="del_event"  
value="删除"></span>
<input type="submit" class="btn btn_ok" value="确定">  
<input type="button" class="btn btn_cancel" value="取消" onClick="$.fancybox.close()"></div> 
    </form> 
</div> 
<script type="text/javascript" src="js/jquery.form.min.js"></script>
<script type="text/javascript">
    $(function(){

    $("#isend").click(function(){
        if($("#p_endtime").css("display")=="none"){
            $("#p_endtime").show();
        }else{
            $("#p_endtime").hide();
        }
        $.fancybox.resize();//调整高度自适应
    });
    
    //提交表单
    $('#add_form').ajaxForm({
        beforeSubmit: showRequest, //表单验证
        success: showResponse //成功返回
    }); 
        $("#del_event").click(function(){ 
            if(confirm("您确定要删除吗？")){ 
                var eventid = $("#eventid").val(); 
                $.post("do.php",{id:eventid,action:'del'},function(msg){ 
                    if(msg==1){//删除成功 
                        $.fancybox.close(); 
                        $('#calendar').fullCalendar('refetchEvents'); //重新获取所有事件数据 
                    }else{ 
                        alert(msg);     
                    } 
                }); 
            } 
        }); 
    });
    
    function showRequest(){
        var events = $("#event").val();
        if(events==''){
            alert("请输入日程内容！");
            $("#event").focus();
            return false;
        }
    }

    function showResponse(responseText, statusText, xhr, $form){
        if(statusText=="success"){  
            if(responseText==1){
                $.fancybox.close();
                $('#calendar').fullCalendar('refetchEvents'); //重新获取所有事件数据
            }else{
                alert(responseText);
            }
        }else{
            alert(statusText);
        }
    }
</script>
<?php }?> 